package com.ruoyi.project.instrument.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.instrument.domain.InsInstrumentUseStatistics;
import com.ruoyi.project.instrument.service.IInsInstrumentUseStatisticsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 仪器使用情况统计Controller
 *
 * @author taney
 * @date 2020-06-09
 */
@AllArgsConstructor
@RestController
@RequestMapping("/instrument/statistics" )
public class InsInstrumentUseStatisticsController extends BaseController {

    private final IInsInstrumentUseStatisticsService iInsInstrumentUseStatisticsService;

    /**
     * 查询仪器使用情况统计列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsInstrumentUseStatistics insInstrumentUseStatistics)
    {
        startPage();
        LambdaQueryWrapper<InsInstrumentUseStatistics> lqw = new LambdaQueryWrapper<InsInstrumentUseStatistics>();
        List<InsInstrumentUseStatistics> list = iInsInstrumentUseStatisticsService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出仪器使用情况统计列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:export')" )
    @Log(title = "仪器使用情况统计" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsInstrumentUseStatistics insInstrumentUseStatistics) {
        LambdaQueryWrapper<InsInstrumentUseStatistics> lqw = new LambdaQueryWrapper<InsInstrumentUseStatistics>(insInstrumentUseStatistics);
        List<InsInstrumentUseStatistics> list = iInsInstrumentUseStatisticsService.list(lqw);
        ExcelUtil<InsInstrumentUseStatistics> util = new ExcelUtil<InsInstrumentUseStatistics>(InsInstrumentUseStatistics. class);
        return util.exportExcel(list, "statistics" );
    }

    /**
     * 获取仪器使用情况统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:query')" )
    @GetMapping(value = "/{instrumentId}" )
    public AjaxResult getInfo(@PathVariable("instrumentId" ) Integer instrumentId) {
        return AjaxResult.success(iInsInstrumentUseStatisticsService.getById(instrumentId));
    }

    /**
     * 新增仪器使用情况统计
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:add')" )
    @Log(title = "仪器使用情况统计" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsInstrumentUseStatistics insInstrumentUseStatistics) {
        return toAjax(iInsInstrumentUseStatisticsService.save(insInstrumentUseStatistics) ? 1 : 0);
    }

    /**
     * 修改仪器使用情况统计
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:edit')" )
    @Log(title = "仪器使用情况统计" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsInstrumentUseStatistics insInstrumentUseStatistics) {
        return toAjax(iInsInstrumentUseStatisticsService.updateById(insInstrumentUseStatistics) ? 1 : 0);
    }

    /**
     * 删除仪器使用情况统计
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:remove')" )
    @Log(title = "仪器使用情况统计" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{instrumentIds}" )
    public AjaxResult remove(@PathVariable Integer[] instrumentIds) {
        return toAjax(iInsInstrumentUseStatisticsService.removeByIds(Arrays.asList(instrumentIds)) ? 1 : 0);
    }

    /**
     * 查询仪器使用情况统计列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:statistics:getSum')")
    @GetMapping("/getSum")
    public AjaxResult getSum(InsInstrumentUseStatistics insInstrumentUseStatistics)
    {
        insInstrumentUseStatistics = iInsInstrumentUseStatisticsService.getSum();
        return AjaxResult.success(insInstrumentUseStatistics);
    }
}
